<script setup>
import {ref} from "vue"
import { ElMessage } from 'element-plus'
import 'element-plus/theme-chalk/el-message.css'
import {useRouter} from "vue-router";
// 表单验证（账号名+密码）
// 1.准备表单对象
const form = ref({
  account: '',
  password: '',
  agree: false
})

// 2.准备规则对象
const rules = {
  account: [
    { required:true, message:'用户名不能为空', trigger:"blur" }
  ],
  password:[
    { required: true,message: '密码不能为空', trigger:"blur" },
    { min: 6, max: 14, message: '密码长度6-14位', trigger:"blur" }
  ],
  agree: [
    {
      validator: (rule, value, callback) => {
        console.log(value)
        // 自定义逻辑
        if (value) {
          callback()
        } else {
          callback (new Error('请勾选用户协议'))
        }
      }
    }
  ]
}

// 3.获取form实例做统一的校验
const formRef = ref(null)
const router = useRouter()
const doLogin = () =>{

  // 调用实例方法
  formRef.value.validate((valid) => {
    // valid：所有的表单都通过校验，才为true
    // 以valid作为判断条件，如果通过校验才执行登录逻辑
    console.log(valid)
    if (valid) {
      //TODO 表单校验，现在默认为true
      // 提示用户
      ElMessage({type:'success',message:'登录成功'})
      // 跳转首页
      router.replace({path:'/'})
    }
  })
}
</script>

<template>
<div class="top">
  <div class="black">
    <p><i class="iconfont icon-daojishi"></i>  2024年618新能源汽车正在热销中！</p>
   <h3> 全国销售热线电话：400-8888-999</h3>
  </div>
</div>
  <header class="login-header">
    <div class="container m-top-20">
      <h1 class="logo">
        <RouterLink to="/">南华汽车</RouterLink>
      </h1>
      <RouterLink class="entry" to="/">
        进入网站首页
        <i class="iconfont icon-angle-right"></i>
        <i class="iconfont icon-angle-right"></i>
        <i class="iconfont icon-angle-right"></i>
      </RouterLink>
    </div>
  </header>
<div class="user-form">
  <div class="layout">
    <div class="login-form">
      <h2 class="centered"><span>登录</span>|<router-link to="/register"><span>注册</span></router-link></h2>

      <el-form ref="formRef" :model="form" :rules="rules" label-position="right" label-width="60px"
               status-icon>
        <el-form-item prop="account"  label="账户">
          <el-input v-model="form.account"/>
        </el-form-item>
        <el-form-item prop="password" label="密码">
          <el-input type="password" v-model="form.password"/>
        </el-form-item>
        <el-form-item prop="agree" label-width="22px">
          <el-checkbox  size="large" v-model="form.agree">
            我已同意隐私条款和服务条款
          </el-checkbox>
        </el-form-item>
        <el-button size="large" class="subBtn" @click="doLogin">点击登录</el-button>
      </el-form>
    </div>
  </div>
</div>
  <footer class="login-footer">
    <div class="container">
      <p>
        <a href="javascript:">关于我们</a>
        <a href="javascript:">帮助中心</a>
        <a href="javascript:;">售后服务</a>
        <a href="javascript:;">专业验收</a>
        <a href="javascript:;">商务合作</a>
        <a href="javascript:;">汽车配件</a>
        <a href="javascript:;">友情链接</a>
      </p>
      <p>CopyRight &copy; 南华汽车网</p>
    </div>
  </footer>
</template>

<style lang="scss">
.black h3,p {
  //text-align: center;
  line-height: 50px;
  margin-left: 30px;
  color: #cac6c6;
}


.black {
  display: flex;
  margin-left: 10px;
}

.top {
  height: 50px;
  background-color: #151515;
}


.login-footer {
  padding: 30px 0 50px;
  background: #151515;

  p {
    text-align: center;
    color: #999;
    padding-top: 20px;

    a {
      line-height: 1;
      padding: 0 10px;
      color: #999;
      display: inline-block;

      ~a {
        border-left: 1px solid #ccc;
      }
    }
  }
}

.login-form h2{
  color:#f64747;
  padding:30px 0;
  text-align: center;
}

.login-form h2 a{
  color:#000;

}
.centered {
  text-align: center;
  margin-top: 30px;
  margin-bottom: 30px;
}

.login-header{
  height: 100px;
}

.user-form{
  background: url(/src/assets/img/loginbg.png) no-repeat center;
  height: 800px;
}

.login-form {
  float: right;
  margin-top: 80px;
  margin-right: 120px;
  background-color: #fff;
  border-radius: 10px;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  transition: all 0.3s ease; /* 添加过渡效果 */
}

.login-form:hover {
  box-shadow: 0 6px 8px rgba(0, 0, 0, 0.2); /* 悬停时阴影效果增强 */
}

.login-form .subBtn {
  /* 按钮悬停效果 */
  transition: background-color 0.3s ease, color 0.3s ease;
}


/* 聚焦动画效果 */
@keyframes fadeIn {
  from { opacity: 10; }
  to { opacity: 1; }
}

.login-form.focused {
  animation: fadeIn 0.5s;
}

.login-form input:focus + label {
  animation: fadeIn 0.5s;
}



.login-form form{
  height: 300px;
  width: 100%;
  padding: 0 64px 32px 64px;
}


.login-header {
  background: #fff;
  border-bottom: 3px solid #fffefe;

  .container {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
  }

  .logo {
    width: 300px;

    a {
      display: block;
      height: 132px;
      width: 100%;
      text-indent: -9999px;
      background: url("/src/assets/img/logo.png") no-repeat center 18px / contain;
    }
  }

  .sub {
    flex: 1;
    font-size: 24px;
    font-weight: normal;
    margin-bottom: 38px;
    margin-left: 20px;
    color: #666;
  }

  .entry {
    width: 120px;
    margin-bottom: 38px;
    font-size: 19px;

    i {
      font-size: 14px;
      color: $nhCarColor;
      letter-spacing: -5px;
    }
  }
}

.form {

  &-item {
    margin-bottom: 28px;

    .input {
      position: relative;
      height: 36px;

      >i {
        width: 34px;
        height: 34px;
        background: #cfcdcd;
        color: #fff;
        position: absolute;
        left: 1px;
        top: 1px;
        text-align: center;
        line-height: 34px;
        font-size: 18px;
      }

      input {
        padding-left: 44px;
        border: 1px solid #cfcdcd;
        height: 36px;
        line-height: 36px;
        width: 100%;

        &.error {
          border-color: $priceColor;
        }

        &.active,
        &:focus {
          border-color: $nhCarColor;
        }
      }

      .code {
        position: absolute;
        right: 1px;
        top: 1px;
        text-align: center;
        line-height: 34px;
        font-size: 14px;
        background: #f5f5f5;
        color: #666;
        width: 90px;
        height: 34px;
        cursor: pointer;
      }
    }

    >.error {
      position: absolute;
      font-size: 12px;
      line-height: 28px;
      color: $priceColor;

      i {
        font-size: 14px;
        margin-right: 2px;
      }
    }
  }

  .agree {
    a {
      color: #069;
    }
  }

  .btn {
    display: block;
    width: 100%;
    height: 40px;
    color: #fff;
    text-align: center;
    line-height: 40px;
    background: $nhCarColor;

    &.disabled {
      background: #cfcdcd;
    }
  }
}

.action {
  padding: 20px 40px;
  display: flex;
  justify-content: space-between;
  align-items: center;

  .url {
    a {
      color: #999;
      margin-left: 10px;
    }
  }
}


.subBtn {
  background: $nhCarColor;
  width: 100%;
  color: #fff;
}

</style>
